import request from '@/utils/request'
import store from '@/store'
// 用户登录
export const loginAPI = ({ mobile, code }) => {
  return request({
    url: '/v1_0/authorizations',
    method: 'POST',
    data: {
      mobile: mobile,
      code: code
    }
  })
}
// 频道_获取用户已选
export const channelAPI = () => {
  return request({
    url: '/v1_0/user/channels',
    headers: {
      Authorization: 'Bearer ' + store.state.token
    }
  })
}
// 频道-获取所有
export const allChannelListAPI = () => {
  return request({
    url: '/v1_0/channels'
  })
}
// 频道-更新用户已选
export const updateChannelListAPI = ({ channelArray, channelId, channelSeq }) => {
  return request({
    url: '/v1_0/user/channels',
    method: 'PUT',
    headers: {
      Authorization: 'Bearer ' + store.state.token
    },
    data: {
      channels: channelArray,
      id: channelId,
      seq: channelSeq
    }
  })
}
// 获取文章列表
export const ArticleListAPI = ({ channelId, timestamp }) => {
  return request({
    url: '/v1_0/articles',
    params: {
      channel_id: channelId,
      timestamp: timestamp || new Date().getTime() + ''
    }
  })
}

// 文章-不感兴趣
export const disLikeAPI = ({ artId }) => {
  return request({
    url: '/v1_0/article/dislikes',
    method: 'POST',
    data: {
      target: artId
    },
    headers: {
      Authorization: 'Bearer ' + store.state.token
    }
  })
}

// 文章-举报
export const reportAPI = ({ artId, type }) => {
  return request({
    url: '/v1_0/article/reports',
    method: 'POST',
    // axios遇到null的值会忽略这对参数
    data: {
      target: artId,
      type: type,
      remark: type === 0 ? '出来吧?王亚飞' : null
    },
    headers: {
      Authorization: 'Bearer ' + store.state.token
    }
  })
}
// 搜索-联想菜单
export const suggesTionAPI = ({ q }) => {
  return request({
    url: '/v1_0/suggestion',
    params: {
      q: q
    }
  })
}
